import { Tabs, TabItem } from '@aws-amplify/ui-react'; import { Fragment } from '@/components/Fragment'; There are four methods to setup the Amazon Cognito resources needed for Amplify Auth. The most common is the Amplify CLI create flow which asks a series of questions and will configure both a User Pool and Identity Pool automatically. The second option is the Amplify CLI import flow which adds an existing Cognito resource into Amplify. The third is to reuse or create a Cognito Identity Pool manually and to add it into your application. Finally the fourth is to pass a credentials provider which obtains the AWS credentials under your control. {({}) => import(`./cognito-callout.mdx`)} > Use the Amplify CLI to automatically configure and manage your Cognito Identity and User Pool for you. FaceLivenessDetector uses Amplify Auth by default to authorize users to perform the Face Liveness check. If you are using Amplify for the first time, follow the instructions for [installing the Amplify CLI](https://docs.amplify.aws/cli/start/install/). #### Set up a new Amplify project ```bash $ amplify init ? Enter a name for the project androidliveness ? Initialize the project with the above configuration? No ? Enter a name for the environment dev ? Choose your default editor: Android Studio ? Choose the type of app that you're building android Please tell us about your project ? Where is your Res directory: app/src/main/res ``` {({ platform }) => import(`./quick-start-pull-cli.mdx`)} #### Push to create the resources ```bash $ amplify push ✔ Successfully pulled backend environment dev from the cloud. Current Environment: dev | Category | Resource name | Operation | Provider plugin | | -------- | ---------------- | --------- | ----------------- | | Auth | androidlive••••• | Create | awscloudformation | ``` _If you have an existing backend, run `amplify pull` to sync your `amplifyconfiguration.json` with your cloud backend._ You should now have an `amplifyconfiguration.json` file in your `app/src/main/res/raw` directory with your latest backend configuration. {({ platform }) => import(`./quick-start-add.${platform}.mdx`)} > If you previously had unmanaged resources that you want to manage with Amplify you can use the CLI to import your Cognito resources. FaceLivenessDetector uses Amplify Auth by default to authorize users to perform the Face Liveness check. Follow the instructions for [importing existing resources](https://docs.amplify.aws/lib/auth/getting-started/q/platform/android/#set-up-backend-resources). {({ platform }) => import(`./quick-start-add.${platform}.mdx`)} > Use this option if you already have a Cognito identity/user pools that you do not want to import to Amplify, or want to manage Cognito resources yourself or with a 3rd party resource management tool. If you already have Cognito set up or do not want to use the Amplify CLI to generate Cognito resources, you can follow the documentation in the [existing resources tab](https://docs.amplify.aws/lib/auth/getting-started/q/platform/android/#set-up-backend-resources). _If you are manually setting up an identity pool in the Cognito console you can follow [this guide](https://docs.aws.amazon.com/cognito/latest/developerguide/getting-started-with-identity-pools.html#create-identity-pool). When setting up the identity pool ensure that access to unauthenticated identities is enabled._ When initially configuring Amplify (assuming you are using no pieces of Amplify other than the FaceLivenessDetector) you can manually create an `amplifyconfiguration.json` file in `app/src/main/res/raw` of this form: ```json { "auth": { "plugins": { "awsCognitoAuthPlugin": { "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "us-east-1:-------------", "Region": "us-east-1" } } } } } } } ``` {({ platform }) => import(`./quick-start-add.${platform}.mdx`)} > Use this option if you want more control over the process of obtaining AWS credentials. By default, FaceLivenessDetector uses Amplify Auth to authorize users to perform the Face Liveness check. You can use your own credentials provider to retrieve credentials from [Amazon Cognito](https://aws.amazon.com/cognito/) or assume a role with [Amazon STS](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html), for example: ```kotlin class MyCredentialsProvider : AWSCredentialsProvider { override fun fetchAWSCredentials( onSuccess: Consumer, onError: Consumer ) { // Fetch the credentials } } ``` ```kotlin FaceLivenessDetector( sessionId = , region = , credentialsProvider = MyCredentialsProvider(), onComplete = { Log.i("MyApp", "Liveness flow is complete") }, onError = { error -> Log.e("MyApp", "Error during Liveness flow", error) } ) ``` {({}) => import(`./credentials-provider-callout.mdx`)} {({ platform }) => import(`./quick-start-add-with-credentials-provider.android.mdx`)}